package com.uchengwang.ui.cm_ui.login.adapter;

import android.content.Context;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.uchengwang.R;
import com.uchengwang.ui.cm_ui.ucity.cityBean.SchoolBean;
import com.zhy.autolayout.utils.AutoUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by U城网 on 2017/5/31.
 * 选择学校
 */

public class SwitchSchoolAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{
    private Context context;
    private List<SchoolBean> schools = new ArrayList<>();//学校
//    private List<AuthenStudentBean> majors = new ArrayList<>();//学院
    private boolean isSchool;//是学校还是院系
    private Bundle bundle;

    public SwitchSchoolAdapter(Context context, boolean isSchool){
        this.context = context;
        this.isSchool = isSchool;
    }


    public void setData(List<SchoolBean> schoolNames){
        this.schools = schoolNames;
        notifyDataSetChanged();
    }

    public List<SchoolBean> getData(){
        return schools;

    }

//    public void setMajorData(List<AuthenStudentBean> majors){
//        this.majors = majors;
//        notifyDataSetChanged();
//    }
//
//    public List<AuthenStudentBean> getMajorData(){
//        return majors;
//
//    }

    public void setBundle(Bundle bundle){
        this.bundle = bundle;
    }


    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = null;
        if (isSchool){
            view = LayoutInflater.from(context).inflate(R.layout.item_switch_school, parent, false);
        }else {
            view = LayoutInflater.from(context).inflate(R.layout.fast_release_item, parent, false);
        }
        return new SwitchSLVH(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder h, final int position) {
        SwitchSLVH holder = (SwitchSLVH) h;
        if (isSchool){
            SchoolBean schoolBean = schools.get(position);
            holder.switch_name.setText(schoolBean.getUniName());

            if (schoolBean.isHavaData()){
                holder.switch_school_tag.setVisibility(View.GONE);
            }else {
                holder.switch_school_tag.setVisibility(View.VISIBLE);
                holder.switch_school_tag.setText("敬请期待...");
            }

            holder.view.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
//                    Intent intent = new Intent(context, ChooseYearAndClassActivity.class);
//                    Bundle bundle = new Bundle();
//                    bundle.putString(BaseConfig.UNI_NAME, schools.get(position).getUniName());//学校名
//                    bundle.putLong(BaseConfig.UNI_ID, schools.get(position).getId());
//                    intent.putExtra(BaseConfig.BUNDLE, bundle);
//                    context.startActivity(intent);
                }
            });
        }else {
//            holder.switch_name.setText(majors.get(position).getUniDepartment());
//            holder.view.setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View view) {
////                    Intent intent = new Intent(context, ChooseYearAndClassActivity.class);
////                    bundle.putString(BaseConfig.COLLEGE, majors.get(position).getUniDepartment());//院系名
////                    intent.putExtra(BaseConfig.BUNDLE, bundle);
////                    context.startActivity(intent);
//                }
//            });
        }


    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public int getItemCount() {
        return schools.size();
    }


     class SwitchSLVH extends RecyclerView.ViewHolder{
        private TextView switch_name, switch_school_tag;
        private View view;

        public SwitchSLVH(View itemView) {
            super(itemView);

            AutoUtils.autoSize(itemView);
            view = itemView;

            if (isSchool){
                switch_name = (TextView) itemView.findViewById(R.id.switch_school_name);
                switch_school_tag   = (TextView) itemView.findViewById(R.id.switch_school_tag);
            }else {
                switch_name = (TextView) itemView.findViewById(R.id.fast_item_text);
            }
        }
    }
}
